<template>
  <div class="view-fill">
    <div
      v-if="
        !purchOrder.visible &&
        !modifyInfo.visible &&
        !revokeInfo.visible &&
        !revokeAndRefuseInfo.visible &&
        !modifyDeliverInfo.visible &&
        !receiptDetailsInfo.visible
      "
      class="app-container-flex"
    >
      <NewFullScreen
        v-model="showDialog"
        title="收货单明细"
        :needOperateAffair="true"
        :operateAffairData="affairTableInfo"
        @returnBack="returnBack"
      >
        <template v-slot:full-button>
          <el-button v-if="canUdate" @click="update()">修改</el-button>
          <el-button v-if="canSubmit" @click="submit()">提交</el-button>
          <el-button v-if="canChcek" @click="check()">审核</el-button>
          <el-button v-if="canReject" @click="reject()">驳回</el-button>
          <el-button v-if="canStorage" @click="storage()">入库</el-button>
          <el-button v-if="canStockAndTransfer" @click="showTransferDetail()"
            >入库并移库</el-button
          >
          <el-button v-if="canCancelPut" @click="_cancelPut()"
            >取消上架</el-button
          >
          <el-button v-if="canOneKeyTransfer" @click="oneKeyTransfer()"
            >一键移库</el-button
          >
          <!-- <el-button v-if="canStockAndPutShelf" @click="stockAndPutShelf"
            >入库并上架</el-button
          > -->
          <el-button v-if="canRevoke" @click="revoke()">撤回</el-button>
          <el-button v-if="canPendStoreRevoke" @click="pendStoreRevoke()"
            >撤销</el-button
          >
          <el-button
            v-if="
              infoList.data.receivingSourceId === -2 &&
              infoList.data.status === 3 &&
              infoList.data.isWithTable === 0 &&
              $permission('receiving:revokable') &&
              isCargoSpaceManage === 0 &&
              (infoList.data.isEstimationStockBusiness === 1
                ? infoList.data.confirmStatus === 0
                : true) &&
              canRevokable
            "
            @click="revokable()"
            >撤回入库</el-button
          >
          <el-button
            v-if="
              !(
                infoList.data.sourceType === 1 && infoList.data.insertType === 1
              ) &&
              infoList.data.receivingSourceId === -2 &&
              infoList.data.status === 3 &&
              infoList.data.isWithTable === 0 &&
              $permission('receiving:insertRevokeAndRefuse') &&
              isCargoSpaceManage === 0 &&
              (infoList.data.isEstimationStockBusiness === 1
                ? infoList.data.confirmStatus === 0
                : true) &&
              canRevokable
            "
            @click="insertRevokeAndRefuse()"
            >撤回入库并拒收</el-button
          >

          <el-button v-if="canPrintQrCode" @click="pringQrCode()"
            >打印二维码</el-button
          >
          <PopoverPrint
            ref="popoverShow"
            title="入库单打印"
            v-model:popoverVisible="popoverVisible"
            :canPrint="canPrintAndExcel"
            :templateArr="templateArr"
            @tempClick="tempClick"
            @print="print"
          ></PopoverPrint>
          <!-- <el-button v-if="canPrintAndExcel" @click="print"
            >入库单打印</el-button
          > -->
          <el-button v-if="canExcelAcceptance" @click="excelAcceptance"
            >验收单导出</el-button
          >
          <PopoverPrint
            ref="popoverShow"
            title="验收单打印"
            v-model:popoverVisible="popoverVisibleAcceptance"
            :canPrint="canPrintAcceptance"
            :templateArr="templateArrAcceptance"
            @tempClick="tempClickAcceptance"
            @print="printAcceptance"
          ></PopoverPrint>
          <!-- <el-button v-if="canPrintAcceptance" @click="printAcceptance"
            >验收单打印</el-button
          > -->
          <el-button v-if="canPrintAndExcel" @click="exportExcel"
            >导出excel</el-button
          >
        </template>
        <div class="model-panel">
          <el-collapse v-model="activeNames">
            <el-collapse-item name="1">
              <template #title>
                <div class="model-panel-title">
                  <p>{{ $t('basic_information') }}</p>
                </div>
              </template>
              <div class="model-panel-body">
                <BasicInformation :info="infoList">
                  <template v-slot:basic-purchOrderNo>
                    <span
                      v-if="
                        $permission('purchOrder:detail') &&
                        infoList.data.purch_application_show
                      "
                      @click="showPurchOrderpDetail(infoList.data.purchOrderId)"
                      >{{ infoList.data.purchOrderNo || '-' }}</span
                    >
                    <span v-else>{{ infoList.data.purchOrderNo || '-' }}</span>
                  </template>
                  <template v-slot:basic-receiptOrderList>
                    <div
                      v-if="
                        infoList.data.receiptOrderList &&
                        infoList.data.receiptOrderList.length > 0
                      "
                    >
                      <span
                        v-for="(item, index) in infoList.data.receiptOrderList"
                        :key="index"
                      >
                        <a
                          v-if="index <= 1"
                          class="slip-edit"
                          @click="showreceiptDetail(item.id)"
                          >{{ item.orderNo }}</a
                        >
                        <span
                          v-if="
                            index < 1 &&
                            infoList.data.receiptOrderList.length > 1
                          "
                          >,</span
                        >
                      </span>
                      <el-dropdown
                        v-if="infoList.data.receiptOrderList.length > 2"
                        @command="showreceiptDetail"
                      >
                        <span class="el-dropdown-link slip-edit">
                          更多
                          <i class="el-icon-arrow-down el-icon--right"></i>
                        </span>
                        <template #dropdown>
                          <el-dropdown-menu>
                            <el-dropdown-item
                              v-for="item in infoList.data.receiptOrderList"
                              :key="item.id"
                              :command="item.id"
                              >{{ item.orderNo }}</el-dropdown-item
                            >
                          </el-dropdown-menu>
                        </template>
                      </el-dropdown>
                    </div>
                    <span v-else>-</span>
                  </template>
                  <template v-slot:basic-invoiceNumber>
                    <div
                      v-if="
                        infoList.data.invoiceNumberList &&
                        infoList.data.invoiceNumberList.length > 0
                      "
                      style="wordwrap: break-word"
                    >
                      <span
                        v-for="(item, index) in infoList.data.invoiceNumberList"
                        :key="index"
                      >
                        <a v-if="index <= 1">{{ item }}</a>
                        <span
                          v-if="
                            index < 1 &&
                            infoList.data.invoiceNumberList.length > 1
                          "
                          >,</span
                        >
                      </span>
                      <el-dropdown
                        v-if="infoList.data.invoiceNumberList.length > 2"
                      >
                        <span class="el-dropdown-link">
                          更多
                          <i class="el-icon-arrow-down el-icon--right"></i>
                        </span>
                        <template #dropdown>
                          <el-dropdown-menu>
                            <el-dropdown-item
                              v-for="(item, index) in infoList.data
                                .invoiceNumberList"
                              :key="index"
                              >{{ item }}</el-dropdown-item
                            >
                          </el-dropdown-menu>
                        </template>
                      </el-dropdown>
                    </div>
                    <span v-else>-</span>
                  </template>
                  <template v-slot:basic-remark>
                    <el-input
                      v-if="
                        (infoList.data.status === 'pend_storage' &&
                          checkRemark) ||
                        (infoList.data.status === 'complete' && checkRemark)
                      "
                      v-model="infoList.data.remark"
                      type="textarea"
                      placeholder="请输入备注"
                      :autosize="{ minRows: 1, maxRows: 5 }"
                      style="width: 50%"
                    />
                    <span
                      v-else
                      :class="
                        (infoList.data.status === 'pend_storage' &&
                          !checkRemark) ||
                        (infoList.data.status === 'complete' && !checkRemark)
                          ? 'slip-edit'
                          : ''
                      "
                      @click="moifyRemark"
                      >{{ infoList.data.remark || '-' }}</span
                    >
                  </template>
                  <template v-slot:basic-filePathList>
                    <span v-if="infoList.data.filePathList">
                      <ele-gallery
                        :lazy="true"
                        :size="150"
                        :source="infoList.data.filePathList"
                        title="附件"
                      ></ele-gallery>
                    </span>
                    <span v-else>-</span>
                  </template>
                </BasicInformation>
              </div>
            </el-collapse-item>
          </el-collapse>
        </div>

        <div class="model-panel">
          <div class="model-panel-title">
            <Tooltip :text="$t('detailInfo')"></Tooltip>
          </div>
          <div class="model-panel-body">
            <pageTable
              :refresh="tableInfo.refresh"
              :init-curpage="tableInfo.initCurpage"
              v-model:data="tableInfo.data"
              :pager="false"
              :summary="true"
              :check-box="false"
              :summary-field-list="tableInfo.summaryFieldList"
              :tab-index="true"
              :field-list="tableInfo.fieldList"
              :isDynamic="true"
              :handle="tableInfo.handle"
              @handleEvent="handleEvent"
            >
            </pageTable>
          </div>
        </div>
      </NewFullScreen>
    </div>
    <purch-order-detail
      v-if="purchOrder.visible"
      v-model:visible="purchOrder.visible"
      :purch-order-id="purchOrder.purchOrderId"
    />
    <receiptManageDetail
      v-if="receiptDetailsInfo.visible"
      :id="receiptDetailsInfo.id"
      v-model:visible="receiptDetailsInfo.visible"
      :title="receiptDetailsInfo.title"
    />
    <ModifyOrder
      v-if="modifyDeliverInfo.visible"
      v-model:visible="modifyDeliverInfo.visible"
      :title="modifyDeliverInfo.title"
      :deliver-id="modifyDeliverInfo.deliverId"
      :order-id="modifyDeliverInfo.orderId"
      :receive-all="modifyDeliverInfo.receiveAll"
      @returnModify="modifyOrderCallback"
    ></ModifyOrder>
    <Modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :order-id="modifyInfo.orderId"
      @returnModify="modifyOrderCallback"
    ></Modify>
    <receivingRevoke
      v-if="revokeInfo.visible"
      :ids="revokeInfo.ids"
      v-model:visible="revokeInfo.visible"
      :order-id="revokeInfo.orderId"
      type="revoke"
      @returnModify="modifyOrderCallback"
    />
    <ReceivingRevoke
      v-if="revokeAndRefuseInfo.visible"
      :ids="revokeAndRefuseInfo.ids"
      v-model:visible="revokeAndRefuseInfo.visible"
      :order-id="revokeAndRefuseInfo.orderId"
      type="revokeAndRefuse"
      @returnModify="modifyOrderCallback"
    />

    <!-- 新增修改弹窗 -->
    <page-dialog
      v-if="dialogInfo.visible"
      :title="dialogInfo.title"
      v-model:visible="dialogInfo.visible"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
      @reset="close"
    >
      <PageForm
        class="paddingBox order-model-formBox flex_wrap_start_start"
        v-model:ref-obj="formInfo.ref"
        :data="formInfo.data"
        :field-list="formInfo.fieldList"
        :rules="formInfo.rules"
        :label-width="formInfo.labelWidth"
      >
        <template v-slot:form-depotName>{{
          dialogInfo.row.depotName
        }}</template>
        <template v-slot:form-deptName>{{ dialogInfo.row.deptName }}</template>
        <template v-slot:form-transferDepotName>
          <el-input
            v-model="formInfo.data.transferDepotName"
            class="not-mongolia"
            type="input"
            :required="true"
            :disabled="true"
            placeholder="请选择入库仓库"
          >
            <template #append>
              <el-icon @click="selectStoreDepot"><MoreFilled /></el-icon>
            </template>
          </el-input>
        </template>
      </PageForm>
      <PageTable
        v-show="dialogTableInfo.data.length"
        ref="dialogTableRef"
        v-model:data="dialogTableInfo.data"
        :field-list="dialogTableInfo.fieldList"
        :highlight-row="true"
        :tab-index="true"
        :check-box="false"
        :pager="false"
        @handleEvent="handleDialogEvent"
      >
      </PageTable>
    </page-dialog>
    <!-- 多人验证弹窗 -->
    <page-dialog
      v-if="manyPeopleInfo.visible"
      :title="manyPeopleInfo.title"
      v-model:visible="manyPeopleInfo.visible"
      :width="manyPeopleInfo.width"
      :bt-loading="manyPeopleInfo.btLoading"
      :bt-list="manyPeopleInfo.btList"
      @reset="manyPeopleClose"
    >
      <el-form ref="tableForm" :model="manyPeopleTable" style="width: 100%">
        <dialog-table
          v-model:data="manyPeopleTable.data"
          :field-list="manyPeopleTable.fieldList"
          :highlight-row="false"
          :tab-index="true"
          :check-box="false"
          :pager="false"
        >
        </dialog-table>
      </el-form>
    </page-dialog>
    <!-- 一键移库 -->
    <page-dialog
      v-if="oneKeyTransferInfo.visible"
      :title="oneKeyTransferInfo.title"
      v-model:visible="oneKeyTransferInfo.visible"
      :width="oneKeyTransferInfo.width"
      :bt-loading="oneKeyTransferInfo.btLoading"
      :bt-list="oneKeyTransferInfo.btList"
      @reset="closeOneKeyTransfer"
    >
      <PageForm
        class="paddingBox order-model-formBox flex_wrap_start_start"
        v-model:ref-obj="oneKeyTransferFormInfo.ref"
        :data="oneKeyTransferFormInfo.data"
        :field-list="oneKeyTransferFormInfo.fieldList"
        :rules="oneKeyTransferFormInfo.rules"
        :label-width="oneKeyTransferFormInfo.labelWidth"
      >
        <template v-slot:form-transferDepotName>
          <el-input
            v-model="oneKeyTransferFormInfo.data.transferDepotName"
            class="not-mongolia"
            type="input"
            :required="true"
            :disabled="true"
            placeholder="请选择入库仓库"
          >
            <template #append>
              <el-icon @click="selectDepot"><MoreFilled /></el-icon>
            </template>
          </el-input>
        </template>
      </PageForm>
      <PageTable
        v-show="oneKeyTransferTableInfo.data.length"
        ref="dialogOneKeyTransferTable"
        v-model:data="oneKeyTransferTableInfo.data"
        :field-list="oneKeyTransferTableInfo.fieldList"
        :highlight-row="true"
        :tab-index="true"
        :check-box="false"
        :pager="false"
        @handleEvent="handleTransferDialogEvent"
      >
      </PageTable>
    </page-dialog>
    <PageDialog
      v-show="dialogUserInfo.visible"
      :title="dialogUserInfo.title"
      v-model:visible="dialogUserInfo.visible"
      :width="dialogUserInfo.width"
      :bt-loading="dialogUserInfo.btLoading"
      :bt-list="dialogUserInfo.btList"
      @reset="handleClose"
    >
      <PageForm
        class="paddingBox order-model-formBox flex_wrap_start_start"
        v-model:ref-obj="formUserInfo.ref"
        :data="formUserInfo.data"
        :field-list="formUserInfo.fieldList"
        :label-width="formUserInfo.labelWidth"
        :list-type-info="listTypeInfo"
      >
      </PageForm>
    </PageDialog>
    <SelectDepot
      v-if="selectDepotInfo.visible"
      v-model:show-dialog="selectDepotInfo.visible"
      :check-box="false"
      :query="selectDepotInfo.query"
      :highlight-row="true"
      :check-lock="true"
      :save-empty="true"
      @callback="selectDepotCallBack"
    />
    <SelectDepot
      v-if="selectTransferDepotInfo.visible"
      v-model:show-dialog="selectTransferDepotInfo.visible"
      :check-box="false"
      :query="selectTransferDepotInfo.query"
      :highlight-row="true"
      :check-lock="true"
      :save-empty="true"
      @callback="selectTransferDepotCallBack"
    />
    <single-product-view
      v-if="singleProductDialog.visible"
      :id="id"
      :query="singleProductDialog.query"
      v-model:show-dialog="singleProductDialog.visible"
      :info="singleProductDialog.info"
      :page-status="canPrintQrCode"
      :info-status="infoList.data.status"
      :isEstimationStockBusiness="infoList.data.isEstimationStockBusiness"
      :confirmStatus="infoList.data.confirmStatus"
      :receiving-source-id="infoList.data.receivingSourceId"
      @showRevokable="showRevokable"
      @showRevokableAndRefuse="showRevokableAndRefuse"
    ></single-product-view>
    <ChosePrinter :visible="printerInfo.visible" @callBack="printerCallBack" />
  </div>
</template>

<script setup name="receivingOrderDetail">
import {
  submitReceivingOrder,
  storageReceivingOrder,
  printCheckOrder,
  exportExcelReceivingOrder,
  stockAndTransferReceivingOrder,
  getReceivingOrderById,
  receivingPrintQrCode,
  getReceivingDetailsList,
  getReceivingOrderPrint,
  revokeReceivingOrder,
  pendStoreRevokeReceivingOrder,
  getDepotCirculationPath,
  stockAndTransferByPath,
  manyPeopleVerification,
  stockAndPutShelfReceivingOrder,
  checkReceivingOrder,
  oneKeyTransferReceivings,
  rejectReceivingOrder,
  cancelPut,
} from '@/api/stock'
const receiptManageDetail = defineAsyncComponent(() =>
  import('@/views/receiptManage/receiptOrder/details')
)
const Modify = defineAsyncComponent(() => import('./modify'))
const PurchOrderDetail = defineAsyncComponent(() =>
  import('../../purch/order/detail.vue')
)
const ModifyOrder = defineAsyncComponent(() => import('./importModifyOrder'))
const SingleProductView = defineAsyncComponent(() =>
  import('./singleProductView')
)
const ReceivingRevoke = defineAsyncComponent(() =>
  import('../receivingRevoke/index')
)
const EleGallery = defineAsyncComponent(() =>
  import('@/components/UploadImg/eleGallery')
)
import { aesEncrypt } from '@/utils/aes-util.js'
import {
  setDisableTime,
  _getCurrentFiscalPeriod,
} from '@/common/js/dateOperation'
import { doPrint } from '@/utils/exportUtil.js'
import { selectByCodeAndDept } from '@/api/report.js'
import { updatePrintCount } from '@/api/mapping'
import { getCustomizeSetting } from '@/api/customize'
import { orderAffairAll } from '@/api/affair'
import { getRrgUserAll, fatchTemplateByCode } from '@/api/base.js'
import { defineAsyncComponent } from 'vue'

const { proxy } = getCurrentInstance()
const emit = defineEmits()

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  id: {
    type: [Number, String],
  },
  isCargoSpaceManage: {
    type: [Number, String],
  },
})

const pages = reactive({
  currentPage: '1',
  pageSize: '20',
})
const activeNames = ref(['1'])
const infoList = reactive({
  data: {},
  fieldList: [
    { label: '收货单号', value: 'orderNo', type: 'text' },
    { label: '采购单号', value: 'purchOrderNo', type: 'slot' },
    { label: '发货单号', value: 'deliverOrderNo', type: 'text' },
    {
      label: '来源收货单号',
      value: 'receivingSourceOrderNo',
      type: 'text',
    },
    { label: '状态', value: 'statusValue', type: 'text' },
    { label: '供应商', value: 'supplierName', type: 'text' },
    { label: '供应商编码', value: 'supplierCode', type: 'text' },
    { label: '仓库', value: 'depotName', type: 'text' },
    { label: '部门', value: 'deptName', type: 'text' },
    { label: '收货人', value: 'receivingUserName', type: 'text' },
    { label: '收货时间', value: 'receivingTime', type: 'text' },
    { label: '入库人', value: 'storeUserName', type: 'text' },
    { label: '入库时间', value: 'storeTime', type: 'text' },
    {
      label: '收货联系人',
      value: 'receivingContacts',
      type: 'text',
    },
    {
      label: '联系人电话',
      value: 'receivingPhone',
      type: 'text',
    },
    { label: '收货地址', value: 'receiveAddressValue', type: 'popover' },
    {
      label: '系统发票号',
      value: 'receiptOrderList',
      type: 'slot',
      // className: "not-br"
    },
    // { label: '发票号码', value: 'invoiceNumber', type: 'slot' },
    {
      label: '验收结论',
      value: 'conclusion',
      type: 'text',
    },
    {
      label: '是否寄售业务',
      value: 'isConsignBusinessValue',
      type: 'text',
      show: proxy.$store.state.permission.systemConfig.is_consign_business == 1,
    },
    {
      label: '是否暂估入库',
      value: 'isEstimationStockBusinessValue',
      type: 'text',
      show:
        proxy.$store.state.permission.systemConfig
          .is_estimation_stock_business == 1,
    },
    {
      label: '确认状态',
      value: 'confirmStatusValue',
      type: 'text',
      show: false,
    },
    { label: '采购部门', value: 'purchDeptName', type: 'text' },
    {
      label: '业务日期',
      value: 'businessDate',
      type: 'text',
    },
    {
      label: '发票号汇总',
      value: 'receiptNumber',
      type: 'text',
    },
    {
      label: '发票总金额',
      value: 'receiptSumAmount',
      type: 'text',
    },
     {
      label: '配送方式',
      value: 'deliveryTypeValue',
      type: 'text',
    },
     {
      label: '配送人',
      value: 'deliveryUser',
      type: 'text',
    },
     {
      label: '配送人电话',
      value: 'deliveryPhone',
      type: 'text',
    },
    { label: '备注', value: 'remark', type: 'slot' },
    {
      label: '附件',
      value: 'filePathList',
      type: 'slot',
      className: 'not-br',
    },
  ],
})
// 过滤相关配置
const filterInfo = reactive({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.id,
      },
    },
    queryParams: {
      orderId: props.id,
    },
  },
})
const purchOrder = reactive({
  visible: false,
  purchOrderId: '',
})
// 表格相关
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  selections: [],
  summaryFieldList: [
    { value: 'qty', formatter: proxy.$fn.qtyFormatter },
    { value: 'refuseQty', formatter: proxy.$fn.qtyFormatter },
    { value: 'deliverQty', formatter: proxy.$fn.qtyFormatter },
    { value: 'pendReceiveQty', formatter: proxy.$fn.qtyFormatter },
    // { value: "price", formatter: proxy.$fn.TripartiteMethod },
    { value: 'sumAmount', formatter: proxy.$fn.TripartiteMethod },
  ],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '150',
    btList: [
      {
        label: '撤回入库',
        event: revokeRow,
        show:
          proxy.$permission('receiving:revokable') &&
          props.isCargoSpaceManage === 0,
        ifRender: ifRenderValue,
      },
      {
        label: '撤回入库并拒收',
        event: insertRevokeAndRefuseRow,
        show:
          proxy.$permission('receiving:insertRevokeAndRefuse') &&
          props.isCargoSpaceManage === 0,
        ifRender: ifRenderValueRevokeAndRefuse,
      },

      {
        label: '个体详情',
        event: singleProductDetails,
        show: true,
      },
    ],
  },
})
const revokeAndRefuseInfo = reactive({
  visible: false,
  orderId: '',
  ids: '',
})

const dialogTableInfo = reactive({
  data: [],
  fieldList: [{ label: '移库路径', value: 'name' }],
})
// 弹窗相关
const dialogInfo = reactive({
  title: '入库并移库',
  visible: false,
  type: '',
  width: '670px',
  btLoading: false,
  row: {},
  path: {},
  btList: [
    { label: '关闭', type: '', icon: '', event: close, show: true },
    {
      label: '保存',
      type: 'primary',
      icon: '',
      disabled: true,
      event: stockAndTransfer,
      saveLoading: false,
      show: true,
    },
  ],
})
const oneKeyTransferInfo = reactive({
  title: '一键移库',
  visible: false,
  type: '',
  width: '670px',
  btLoading: false,
  row: {},
  path: {},
  btList: [
    {
      label: '关闭',
      type: '',
      icon: '',
      event: closeOneKeyTransfer,
      show: true,
    },
    {
      label: '保存',
      type: 'primary',
      icon: '',
      disabled: true,
      event: oneKeyTransferSave,
      saveLoading: false,
      show: true,
    },
  ],
})
const oneKeyTransferTableInfo = reactive({
  data: [],
  fieldList: [{ label: '移库路径', value: 'name' }],
})
const dialogUserInfo = reactive({
  visible: false,
  title: '选择上架人员',
  btLoading: false,
  width: '400px',
  btList: [
    {
      label: '关闭',
      event: handleClose,
      show: true,
    },
    {
      label: '保存',
      type: 'primary',
      event: saveputShelfUser,
      show: true,
    },
  ],
})
const formUserInfo = reactive({
  data: {
    id: '',
    putShelfUser: -2,
  },
  fieldList: [
    {
      label: '姓名',
      value: 'putShelfUser',
      type: 'select',
      filterable: true,
      list: 'userList',
      event: 'userName',
    },
  ],
})
const listTypeInfo = reactive({
  userList: [],
})
const manyPeopleInfo = reactive({
  title: '多人验证',
  visible: false,
  type: '',
  width: '670px',
  btLoading: false,
  row: {},
  path: {},
  btList: [
    {
      label: '关闭',
      type: '',
      icon: '',
      event: manyPeopleClose,
      show: true,
    },
    {
      label: '保存',
      type: 'primary',
      icon: '',
      event: manyPeopleSave,
      saveLoading: false,
      show: true,
    },
  ],
})
const manyPeopleTable = reactive({
  data: [],
  fieldList: [
    {
      label: '账号',
      value: 'username',
      type: 'inputRules',
      rules: { required: true, message: '请输入账号', trigger: 'blur' },
    },
    {
      label: '密码',
      value: 'password',
      type: 'password',
      rules: { required: true, message: '请输入密码', trigger: 'blur' },
    },
  ],
})
const selectDepotInfo = reactive({
  visible: false,
  query: {
    depotAuth: 'id',
    status: 1,
    idNot: '',
    useTypeId: 1,
    isCargoSpaceManage: '0',
  },
})
const selectTransferDepotInfo = reactive({
  visible: false,
  query: {
    depotAuth: 'id',
    status: 1,
    idNot: '',
    useTypeId: 1,
    isCargoSpaceManage: '0',
  },
})
// 表单相关
const formInfo = reactive({
  ref: null,
  data: {
    id: '',
    transferDepotName: '',
    transferDeptName: '',
    transferDepotId: '',
    transferDeptId: '',
  },
  fieldList: [
    {
      label: '入库仓库',
      value: 'depotName',
      type: 'slot',
    },
    {
      label: '入库部门',
      value: 'deptName',
      type: 'slot',
    },
    {
      label: '移库入库仓库',
      value: 'transferDepotName',
      type: 'slot',
    },
    {
      label: '移库入库部门',
      value: 'transferDeptName',
      type: 'input',
      placeholder: '入库部门',
      disabled: true,
    },
    {
      label: '业务日期',
      value: 'businessDate',
      type: 'date',
      clearable: false,
    },
  ],
  rules: {
    transferDepotName: [
      {
        required: true,
        message: '请输入仓库',
        trigger: 'blur',
      },
    ],
    businessDate: [
      { required: true, message: '请选择业务日期', target: 'change' },
    ],
  },
  labelWidth: '120px',
})
// 表单相关
const oneKeyTransferFormInfo = reactive({
  ref: null,
  data: {
    id: '',
    transferDepotName: '',
    transferDeptName: '',
    transferDepotId: '',
    transferDeptId: '',
    businessDate: '',
  },
  fieldList: [
    {
      label: '移库入库仓库',
      value: 'transferDepotName',
      type: 'slot',
    },
    {
      label: '移库入库部门',
      value: 'transferDeptName',
      type: 'input',
      placeholder: '入库部门',
      disabled: true,
    },
    {
      label: '业务日期',
      value: 'businessDate',
      type: 'date',
      clearable: false,
    },
  ],
  rules: {
    transferDepotName: [
      {
        required: true,
        message: '请输入仓库',
        trigger: 'blur',
      },
    ],
    businessDate: [
      { required: true, message: '请选择业务日期', target: 'change' },
    ],
  },
  labelWidth: '120px',
})
const affairTableInfo = reactive({
  api: orderAffairAll,
  query: {
    orderType: 15,
    orderId: props.id,
    sort: 'operate_time desc,id desc',
  },
})
//修改或新增弹框信息
const modifyDeliverInfo = reactive({
  visible: false,
  title: '',
  orderId: '',
  deliverId: '',
  type: '',
})
const modifyInfo = reactive({
  visible: false,
  title: '',
  orderId: '',
})
const receiptDetailsInfo = reactive({
  id: '',
  visible: false,
})
let singleProductDialog = ref({
  visible: false,
  query: {},
  info: {},
})
const printerInfo = reactive({
  visible: false,
  data: {},
})
const revokeInfo = reactive({
  visible: false,
  orderId: '',
  ids: '',
})
const checkRemark = ref(false)
let disStartDate = ref('')
let disEndDate = ref('')
let disStartDate2 = ref('')
let disEndDate2 = ref('')

const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emit('update:visible', newValue) // 更新父组件visible
  },
})
const canUdate = computed(() => {
  return proxy.$permission('receiving:update') && infoList.data.status === 1
})
const canSubmit = computed(() => {
  return proxy.$permission('receiving:submit') && infoList.data.status === 1
})
const canChcek = computed(() => {
  return (
    proxy.$store.state.permission.systemConfig.material_receiving_approval ===
      1 &&
    proxy.$permission('receiving:check') &&
    infoList.data.status === 6
  )
})
const canReject = computed(() => {
  return (
    proxy.$store.state.permission.systemConfig.material_receiving_approval ===
      1 &&
    proxy.$permission('receiving:reject') &&
    infoList.data.status === 6
  )
})
const canStorage = computed(() => {
  return proxy.$permission('receiving:storage') && infoList.data.status === 2
})
const canRevokable = computed(() => {
  let arr = tableInfo.data.filter((item) => item.canInvalidCalcQty > 0)
  return arr.length
})
const canStockAndTransfer = computed(() => {
  return (
    proxy.$permission('receiving:stockAndTransfer') &&
    infoList.data.status === 2 &&
    infoList.data.isCargoSpaceManage === 0
  )
})
const canCancelPut = computed(() => {
  return proxy.$permission('receiving:cancelPut') && infoList.data.status === 7
})
const canOneKeyTransfer = computed(() => {
  return (
    proxy.$permission('receiving:oneKeyTransfer') &&
    infoList.data.status === 3 &&
    infoList.data.isCargoSpaceManage === 0
  )
})
const canStockAndPutShelf = computed(() => {
  return (
    proxy.$permission('receiving:storeAndPutShelf') &&
    infoList.data.status === 2 &&
    infoList.data.isCargoSpaceManage === 1
  )
})
const canRevoke = computed(() => {
  if (
    proxy.$store.state.permission.systemConfig.material_receiving_approval === 1
  ) {
    return proxy.$permission('receiving:revoke') && infoList.data.status === 6
  }
  return proxy.$permission('receiving:revoke') && infoList.data.status === 2
})
const canPendStoreRevoke = computed(() => {
  return (
    proxy.$permission('receiving:backOut') &&
    infoList.data.status === 2 &&
    proxy.$store.state.permission.systemConfig.material_receiving_approval == 1
  )
})
const canPrintQrCode = computed(() => {
  return (
    proxy.$permission('receiving:printCode') &&
    infoList.data.status !== 1 &&
    infoList.data.receiveOrderStockType !== 1
  )
})
const canPrintAndExcel = computed(() => {
  return proxy.$permission('receiving:printCode') && infoList.data.status !== 1
})
const canPrintAcceptance = computed(() => {
  return (
    proxy.$permission('receiving:printAcceptance') &&
    (infoList.data.status === 2 || infoList.data.status === 3)
  )
})
const canExcelAcceptance = computed(() => {
  return (
    proxy.$permission('receiving:excelAcceptance') &&
    (infoList.data.status === 2 || infoList.data.status === 3)
  )
})
watch(
  () => tableInfo.data,
  () => {
    //发票号汇总
    let receiptNumberArr = []
    let receiptSumAmount = 0
    tableInfo.data.forEach((row) => {
      if (row.receiptNumber) {
        receiptNumberArr.push(row.receiptNumber)
      }
      if (receiptNumberArr.length) {
        receiptNumberArr = [...new Set(receiptNumberArr)]
      }
      row.receiptSumAmount = proxy.$fn.accMul(
        row.receiptPrice || 0,
        row.receiptCalcQty || 0
      )
      receiptSumAmount = proxy.$fn.accAdd(
        row.receiptSumAmount,
        receiptSumAmount
      )
    })
    infoList.data['receiptNumber'] =
      infoList.data['receiptNumber'] || String(receiptNumberArr)
    infoList.data['receiptSumAmount'] =
      infoList.data['receiptSumAmount'] || receiptSumAmount
  },
  {
    deep: true,
  }
)
let collapseHeight = ref()
const theResizeObserver = ref()
watch(
  () => collapseHeight.value,
  (val) => {
    if (val >= 340 || val <= 52) {
      proxy.$store.dispatch('app/togglePageTable')
    }
  },
  {
    immediate: true,
    deep: true,
  }
)
function handleResize(entries) {
  collapseHeight.value =
    document.getElementsByClassName('el-collapse')[0].offsetHeight
}
onMounted(() => {
  theResizeObserver.value = new ResizeObserver(handleResize)
  const theElement = document.getElementsByClassName('el-collapse')[0]
  theResizeObserver.value.observe(theElement)
})
onBeforeUnmount(() => {
  theResizeObserver.value.disconnect()
})
let obj = {
  price: {
    label: '单价',
    value: 'price',
    type: 'column',
    columnType: 'price',
    permission: !proxy.$permission('receiving:price'),
    formatter: proxy.$fn.TripartiteMethod,
    hidden: true,
  },
  sumAmount: {
    label: '总金额',
    value: 'sumAmount',
    type: 'column',
    formatter: proxy.$fn.TripartiteMethod,
    columnType: 'price',
    permission: !proxy.$permission('receiving:price'),
    hidden: true,
  },
  defaultSupplierPrice: {
    label: '默认供应商价格',
    value: 'defaultSupplierPrice',
    type: 'column',
    componentType: 'price',
    permission: !proxy.$permission('receiving:price'),
    formatter: proxy.$fn.TripartiteMethod,
    hidden: true,
    show: false,
  },
  defaultPrice: {
    label: '默认价格',
    value: 'defaultPrice',
    type: 'column',
    componentType: 'price',
    permission: !proxy.$permission('receiving:price'),
    formatter: proxy.$fn.TripartiteMethod,
    hidden: true,
  },
}
tableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...obj,
})
getCustomize()
getUserList()
function insertRevokeAndRefuse() {
  revokeAndRefuseInfo.orderId = infoList.data.id
  revokeAndRefuseInfo.ids = ''
  validateRevokeAndRefuse()
}
function insertRevokeAndRefuseRow(row) {
  revokeAndRefuseInfo.orderId = infoList.data.id
  revokeAndRefuseInfo.ids = row.groupConcatIds
  validateRevokeAndRefuse()
}
function showRevokableAndRefuse(id) {
  revokeAndRefuseInfo.orderId = infoList.data.id
  revokeAndRefuseInfo.ids = id
  revokeAndRefuseInfo.visible = true
}
function validateRevokeAndRefuse(row) {
  getReceivingDetailsList(filterInfo.query).then((resp) => {
    if (resp && resp.success) {
      let data = resp.data
      if (row && row.id) {
        let item = data.find((item) => item.id === row.id)
        if (item.canInvalidCalcQty > 0) {
          revokeAndRefuseInfo.visible = true
        } else {
          proxy.$message({
            message: '无可撤回数量，请刷新数据',
            type: 'warning',
            duration: 3500,
            showClose: true,
          })
          return
        }
      } else {
        let arr = data.filter((item) => item.canInvalidCalcQty > 0)
        if (arr.length) {
          revokeAndRefuseInfo.visible = true
        } else {
          proxy.$message({
            message: '无可撤回数量，请刷新数据',
            type: 'warning',
            duration: 3500,
            showClose: true,
          })
          return
        }
      }
    }
  })
}

function selectDepot() {
  selectTransferDepotInfo.query.idNot = infoList.data.depotId
  selectTransferDepotInfo.visible = true
}
function selectTransferDepotCallBack(data = undefined) {
  if (data && data.id) {
    oneKeyTransferFormInfo.data['transferDepotName'] = data.name
    oneKeyTransferFormInfo.data['transferDepotId'] = data.id
    oneKeyTransferFormInfo.data['transferDeptName'] = data.deptName || ''
    oneKeyTransferFormInfo.data['transferDeptId'] = data.deptId || ''
    getTransfeStorePath()
  } else {
    oneKeyTransferFormInfo.data['transferDepotName'] = ''
    oneKeyTransferFormInfo.data['transferDepotName'] = ''
    oneKeyTransferFormInfo.data['transferDepotName'] = ''
    oneKeyTransferFormInfo.data['transferDepotName'] = ''
  }
}
function handleTransferDialogEvent(event, data) {
  if (event === 'tableClickRow' && data) {
    oneKeyTransferInfo.path = data.value
  }
}
function getTransfeStorePath() {
  let param = {
    firstDepotId: infoList.data.depotId,
    lastDepotId: oneKeyTransferFormInfo.data.transferDepotId,
  }
  getDepotCirculationPath(param).then((res) => {
    if (res && res.success) {
      oneKeyTransferTableInfo.data = res.data
      if (res.data.length > 0) {
        oneKeyTransferInfo.path = res.data[0].value
        proxy.$refs.dialogOneKeyTransferTable.setCurrentRow(res.data[0], true)
      }
      oneKeyTransferInfo.btList[1].disabled = false
    }
  })
}
function closeOneKeyTransfer() {
  oneKeyTransferFormInfo.data.transferDepotId = ''
  oneKeyTransferFormInfo.data.transferDeptId = ''
  oneKeyTransferFormInfo.data.transferDepotName = ''
  oneKeyTransferFormInfo.data.transferDeptName = ''
  oneKeyTransferInfo.visible = false
  oneKeyTransferInfo.btList[1].disabled = true
  oneKeyTransferTableInfo.data = []
}
function oneKeyTransferSave() {
  //一键移库
  oneKeyTransferFormInfo.ref.validate((valid) => {
    if (valid) {
      let params = {
        ...infoList.data,
        transferDepotId: oneKeyTransferFormInfo.data.transferDepotId,
        transferDeptId: oneKeyTransferFormInfo.data.transferDeptId,
        path: oneKeyTransferTableInfo.data.length
          ? oneKeyTransferInfo.path
          : [],
        businessDate: oneKeyTransferFormInfo.data.businessDate,
      }
      oneKeyTransferReceivings(params).then((res) => {
        if (res && res.success) {
          getMain()
          getList()
          closeOneKeyTransfer()
        }
      })
    }
  })
}
function oneKeyTransfer() {
  //一键移库
  oneKeyTransferFormInfo.data = {}
  oneKeyTransferInfo.visible = true
  setDisableTime(oneKeyTransferFormInfo.fieldList, disStartDate, disEndDate)
  setBusinessDate()
}
async function setBusinessDate() {
  oneKeyTransferFormInfo.data.businessDate = await _getCurrentFiscalPeriod(
    oneKeyTransferFormInfo.fieldList,
    proxy,
    disStartDate,
    disEndDate
  )
}
//获取人员列表
function getUserList() {
  let params = {
    sort: 'create_time desc',
  }
  getRrgUserAll(params).then((res) => {
    if (res && res.success) {
      let arr = [{ key: '暂不选择', value: -2, userName: '' }]
      if (res.data && res.data.length) {
        let data = res.data.map((item) => {
          return {
            key: item.name,
            value: item.id,
            userName: item.userName,
          }
        })
        listTypeInfo.userList = arr.concat(data)
      }
    }
  })
}
//上架
function saveputShelfUser() {
  stockAndPutShelfReceivingOrder(formUserInfo.data).then((res) => {
    if (res && res.success) {
      getMain()
      getList()
      handleClose()
    }
  })
}
//关闭选择拣货人员弹窗
function handleClose() {
  dialogUserInfo.visible = false
  formUserInfo.data = {
    id: '',
    putShelfUser: -2,
  }
}
function ifRenderValue(row) {
  return (
    infoList.data.receivingSourceId === -2 &&
    infoList.data.status === 3 &&
    infoList.data.isWithTable === 0 &&
    (infoList.data.isEstimationStockBusiness === 1
      ? infoList.data.confirmStatus === 0
      : true) &&
    row.canInvalidCalcQty > 0
  )
}
function ifRenderValueRevokeAndRefuse(row) {
  return (
    !(infoList.data.sourceType === 1 && infoList.data.insertType === 1) &&
    infoList.data.receivingSourceId === -2 &&
    infoList.data.status === 3 &&
    infoList.data.isWithTable === 0 &&
    (infoList.data.isEstimationStockBusiness === 1
      ? infoList.data.confirmStatus === 0
      : true) &&
    row.canInvalidCalcQty > 0
  )
}
function revoke() {
  let ids = [infoList.data.id]
  revokeReceivingOrder(ids).then((res) => {
    if (res && res.success) {
      getMain()
      getList()
    }
  })
}
function pendStoreRevoke() {
  let ids = [infoList.data.id]
  pendStoreRevokeReceivingOrder(ids).then((res) => {
    if (res && res.success) {
      getMain()
      getList()
    }
  })
}
function revokable() {
  revokeInfo.orderId = infoList.data.id
  revokeInfo.ids = ''
  validateRevoke()
}
function revokeRow(row) {
  //撤回
  revokeInfo.orderId = infoList.data.id
  revokeInfo.ids = row.groupConcatIds
  validateRevoke(row)
}
function showRevokable(id) {
  //撤回
  revokeInfo.orderId = infoList.data.id
  revokeInfo.ids = id
  revokeInfo.visible = true
}
function validateRevoke(row) {
  getReceivingDetailsList(filterInfo.query).then((resp) => {
    if (resp && resp.success) {
      let data = resp.data
      if (row && row.id) {
        let item = data.find((item) => item.id === row.id)
        if (item.canInvalidCalcQty > 0) {
          revokeInfo.visible = true
        } else {
          proxy.$message({
            message: '无可撤回数量，请刷新数据',
            type: 'warning',
            duration: 3500,
            showClose: true,
          })
          return
        }
      } else {
        let arr = data.filter((item) => item.canInvalidCalcQty > 0)
        if (arr.length) {
          revokeInfo.visible = true
        } else {
          proxy.$message({
            message: '无可撤回数量，请刷新数据',
            type: 'warning',
            duration: 3500,
            showClose: true,
          })
          return
        }
      }
    }
  })
}

function moifyRemark() {
  checkRemark.value = true
}
function returnBack() {
  emit('returnBack', false)
}
function singleProductDetails(row) {
  // 个体详情
  const params = {
    batchNumber: row.batchNumber,
    receivingOrderId: props.id,
    productId: row.productId,
  }
  singleProductDialog.value = {
    visible: true,
    query: params,
    info: row,
  }
}
function showPurchOrderpDetail(purchOrderId) {
  purchOrder.purchOrderId = purchOrderId
  purchOrder.visible = true
}
// 获取列表
function getList() {
  getReceivingDetailsList(filterInfo.query).then((res) => {
    if (res && res.success) {
      tableInfo.data = res.data
    }
  })
}
function getMain() {
  getReceivingOrderById(props.id).then((resp) => {
    if (resp && resp.success) {
      infoList.data = resp.data
      console.log(infoList.data)
      infoList.data.invoiceNumberList = infoList.data.invoiceNumber
        ? infoList.data.invoiceNumber.indexOf(',') !== -1
          ? infoList.data.invoiceNumber.split(',')
          : [infoList.data.invoiceNumber]
        : []
      let item = infoList.fieldList.filter(
        (item) => item.value === 'confirmStatusValue'
      )
      if (item.length) {
        item[0].show =
          resp.data.isEstimationStockBusiness == 1 &&
          proxy.$store.state.permission.systemConfig
            .is_estimation_stock_business == 1
      }
    }
  })
}
// 编辑
function update() {
  if (infoList.data.insertType === 1 && infoList.data.sourceType === 1) {
    //手动新增
    modifyInfo.orderId = infoList.data.id
    modifyInfo.visible = true
    modifyInfo.title = '修改收货单'
  } else {
    modifyDeliverInfo.orderId = infoList.data.id
    modifyDeliverInfo.deliverId = infoList.data.deliverId
    modifyDeliverInfo.visible = true
    modifyDeliverInfo.receiveAll = infoList.data.receiveAll
    modifyDeliverInfo.title = '修改收货单'
  }
}
// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.selections = [...data]
      break
  }
}
//提交
function submit() {
  const ids = [props.id]
  submitReceivingOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getMain()
      getList()
    }
  })
}
function check() {
  const ids = [props.id]
  checkReceivingOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getMain()
      getList()
    }
  })
}
function reject() {
  const ids = [props.id]
  rejectReceivingOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getMain()
      getList()
    }
  })
}
//入库
function storage() {
  const ids = [props.id]
  storageReceivingOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getMain()
      getList()
    }
  })
}
function stockAndPutShelf() {
  //方法名称
  dialogUserInfo.visible = true
  formUserInfo.data.id = props.id
}
//打印整单的二维码
function pringQrCode() {
  let ids = []
  ids.push(props.id)
  if (ids.length > 0) {
    receivingPrintQrCode(ids).then((resp) => {
      if (resp && resp.success) {
        printerInfo.visible = true
        printerInfo.data = resp.data
      }
    })
  }
}
function printerCallBack(printer) {
  if (printer !== false) {
    proxy.$print.buildRenderBarCode(printerInfo.data, printer)
  }
  printerInfo.visible = false
}
function modifyOrderCallback() {
  getCustomize()
}
//导出excel
function exportExcel() {
  exportExcelReceivingOrder(filterInfo.query).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
const templateArr = ref([])
const popoverVisible = ref(false)
//打印
function print() {
  selectByCodeAndDept({
    tempCode: 'receivingDetail',
    deptId: infoList.data.deptId,
  }).then((res) => {
    if (res && res.success) {
      templateArr.value = res.data
      popoverVisible.value = true
      // 一条数据则直接打印
      if (templateArr.value.length === 1) {
        proxy.$refs.popoverShow.hidePopover()
        doPrint({
          name: templateArr.value[0].ureportName,
          params: {
            orderId: props.id,
            orderNo: infoList.data.orderNo,
          },
          callback: printCallback,
          printCount: true,
          data: {},
        })
      }
    }
  })
  /* const receiveOrderStockType = infoList.data.receiveOrderStockType ? 0 : 1
  fatchTemplateByCode({
    resourceCode: 'receivingOrder:print',
    isDefault: receiveOrderStockType,
  }).then((res) => {
    if (res && res.success) {
      let temp = proxy.$fn.getPrintTemp(res.data[0])
      getPirntData(temp)
    }
  }) */
}
function tempClick(item) {
  doPrint({
    name: item.ureportName,
    params: {
      orderId: props.id,
      orderNo: infoList.data.orderNo,
    },
    callback: printCallback,
    printCount: true,
    data: {},
  })
  popoverVisible.value = false
}
function printCallback() {
  try {
    // 打印成功增加打印次数
    updatePrintCount({
      orderNo: infoList.data.orderNo,
      printCode: 'receiving:printCode',
      orderId: props.id,
      orderType: 15,
    })
  } catch (error) {}
}
//验收单导出
function excelAcceptance() {
  filterInfo.query.queryParams.isPrintAcceptance = 1
  exportExcelReceivingOrder(filterInfo.query).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
      filterInfo.query.queryParams = {
        orderId: props.id,
      }
    }
  })
}
const templateArrAcceptance = ref([])
const popoverVisibleAcceptance = ref(false)
//打印
function printAcceptance() {
  selectByCodeAndDept({
    tempCode: 'receivingAcceptanceDetail',
    deptId: infoList.data.deptId,
  }).then((res) => {
    if (res && res.success) {
      templateArrAcceptance.value = res.data
      popoverVisibleAcceptance.value = true
      // 一条数据则直接打印
      if (templateArrAcceptance.value.length === 1) {
        doPrint({
          name: templateArrAcceptance.value[0].ureportName,
          params: {
            orderId: props.id,
            orderNo: infoList.data.orderNo,
          },
          callback: printCallbackAcceptance,
          printCount: true,
          data: {},
        })
      }
    }
  })
}
function printCallbackAcceptance() {
  try {
    // 打印成功增加打印次数
    updatePrintCount({
      orderNo: infoList.data.orderNo,
      printCode: 'receiving:printAcceptance',
      orderId: props.id,
      orderType: 15,
    })
  } catch (error) {}
}
function tempClickAcceptance(item) {
  doPrint({
    name: item.ureportName,
    params: {
      orderId: props.id,
      orderNo: infoList.data.orderNo,
    },
    callback: printCallbackAcceptance,
    printCount: true,
    data: {},
  })
  popoverVisibleAcceptance.value = false
}
function getPirntData(temp) {
  let params = {
    tableKey:
      'stockReceivingOrderDetails-com.slip.spd.entity.vo.stock.ReceivingOrderDetailVO',
    orderIds: [props.id],
  }
  getReceivingOrderPrint(params).then((res) => {
    if (res.success && res) {
      let data = proxy.$fn.deepClone(res.data)
      let newData = data.map((item) => {
        return {
          ...item,
          ...item.orderInfo,
        }
      })
      proxy.$lodop.preview(temp, newData, !proxy.$permission('receiving:price'))
    }
  })
}
//打印到货验收单
function printCkOrder() {
  printCheckOrder(infoList.data.id).then((resp) => {
    if (resp && resp.success) {
      proxy.$print.printReceivingCheckOrder(resp.data)
    }
  })
}
function showreceiptDetail(id) {
  receiptDetailsInfo.visible = true
  receiptDetailsInfo.id = id
}
//多人验证弹窗关闭
function manyPeopleClose() {
  manyPeopleInfo.visible = false
  manyPeopleTable.data = []
}
//关闭弹窗
function close() {
  formInfo.data.id = ''
  formInfo.data.transferDepotId = ''
  formInfo.data.transferDeptId = ''
  formInfo.data.transferDepotName = ''
  formInfo.data.transferDeptName = ''
  selectDepotInfo.query.idNot = ''
  dialogInfo.visible = false
  dialogTableInfo.data = []
  dialogInfo.btList[1].disabled = true
}

//选择仓库
function selectStoreDepot() {
  selectDepotInfo.query.idNot = dialogInfo.row.depotId
  selectDepotInfo.visible = true
}
function selectDepotCallBack(data = undefined) {
  if (data && data.id) {
    formInfo.data.transferDepotId = data.id
    formInfo.data.transferDepotName = data.name
    formInfo.data.transferDeptName = data.deptName || ''
    formInfo.data.transferDeptId = data.deptId || ''
    dialogInfo.btList[1].disabled = true
    getStorePath()
  } else {
    formInfo.data.transferDepotId = ''
    formInfo.data.transferDepotName = ''
    formInfo.data.transferDeptName = ''
    formInfo.data.transferDeptId = ''
  }
}
function getStorePath() {
  let param = {
    firstDepotId: dialogInfo.row.depotId,
    lastDepotId: formInfo.data.transferDepotId,
  }
  getDepotCirculationPath(param).then((res) => {
    if (res && res.success) {
      dialogTableInfo.data = res.data
      if (res.data.length > 0) {
        dialogInfo.path = res.data[0].value
        proxy.$refs.dialogTableRef.setCurrentRow(res.data[0], true)
      }
      dialogInfo.btList[1].disabled = false
    }
  })
}
function handleDialogEvent(event, data) {
  if (event === 'tableClickRow') {
    dialogInfo.path = data.value
  }
}

//查看明细
function showTransferDetail() {
  dialogInfo.row = infoList.data
  dialogInfo.visible = true
  formInfo.data.id = props.id
  selectDepotInfo.query.idNot = infoList.data.depotId
  setDisableTime(formInfo.fieldList, disStartDate2, disEndDate2)
  setBusinessDate2()
}
//取消上架
function _cancelPut() {
  proxy
    .$confirm('确认取消上架吗？', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    })
    .then(() => {
      cancelPut(props.id).then((resp) => {
        if (resp && resp.success) {
          getMain()
          getList()
        }
      })
    })
    .catch(() => {})
}
async function setBusinessDate2() {
  formInfo.data.businessDate = await _getCurrentFiscalPeriod(
    formInfo.fieldList,
    proxy,
    disStartDate2,
    disEndDate2
  )
}
//入库并移库
function stockAndTransfer() {
  formInfo.ref.validate((valid) => {
    if (valid) {
      let many_people_verification =
        proxy.$store.state.permission.systemConfig.many_people_verification
      if (Number(many_people_verification) > 0) {
        manyPeopleTable.data = []
        for (let i = 0; i < Number(many_people_verification); i++) {
          manyPeopleTable.data.push({ username: '', password: '' })
        }
        manyPeopleInfo.visible = true
        return
      }
      submitStockAndTransfer()
    }
  })
}
//多人验证保存
function manyPeopleSave() {
  proxy.$refs.tableForm.validate((valid) => {
    if (valid) {
      let data = manyPeopleTable.data
      let newData = data.map((item) => {
        let encryptPassword = aesEncrypt(item.password, item.username.trim())
        return {
          username: item.username.trim(),
          password: encryptPassword.toString(),
        }
      })
      let param = {
        userList: newData,
        lastDepotId: formInfo.data.transferDepotId,
      }
      manyPeopleVerification(param).then((res) => {
        if (res && res.success) {
          manyPeopleClose()
          submitStockAndTransfer()
        }
      })
    }
  })
}
function submitStockAndTransfer() {
  let id = formInfo.data.id
  if (dialogTableInfo.data.length) {
    let params = {
      id: id,
      path: dialogInfo.path,
      businessDate: formInfo.data.businessDate,
    }
    stockAndTransferByPath(params).then((resp) => {
      if (resp && resp.success) {
        getMain()
        getList()
        close()
      }
    })
  } else {
    let params = {
      id: id,
      transferDeptId: formInfo.data.transferDeptId,
      transferDepotId: formInfo.data.transferDepotId,
      businessDate: formInfo.data.businessDate,
    }
    stockAndTransferReceivingOrder(params).then((resp) => {
      if (resp && resp.success) {
        getMain()
        getList()
        close()
      }
    })
  }
}
function getCustomize() {
  let param = {
    tableKey:
      'stockReceivingOrderDetails-com.slip.spd.entity.vo.stock.ReceivingOrderDetailVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.query.customizeUserVO = data
      let obj = proxy.$fn.setFieldList(tableInfo.fieldList, data.detail)
      tableInfo.fieldList = obj
      getMain()
      getList()
    }
  })
}
</script>

<style scoped></style>
